package search;

import comment.Comment;

/**
 *create by tbj
 */
	//使用递归二分查找
public class BinarySearch_deep {
	private static int _search(int[] a,int l,int r,int target){
		if(l>r){
			return -1;
		}
		int mid=l+(r-l)/2;
		if(a[mid]==target){
			return mid;
		}else if(a[mid]<target){
			return _search(a, mid+1, r, target);
		}else{
			return _search(a, l, mid-1, target);
		}
		
	}
	public static int search(int[] a,int target){
		return _search(a,0,a.length-1,target);
	}
	public static void main(String[] args) {
		int[] a=Comment.getOrderedArray(10);
		System.out.println(BinarySearch_deep.search(a, 2));
	}
}
